package com.ape.mapsa.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import com.ape.mapsa.produccion.constants.TipoMaquina;

@FacesConverter(value = "TipoMaquinaConverter")
public class TipoMaquinaConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		TipoMaquina[] tiposmaquina = TipoMaquina.values();
		for (int i = 0; i < tiposmaquina.length; i++) {
			if (tiposmaquina[i].getNombre().equals(value)) {
				return tiposmaquina[i];
			}
		}
		return null;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object value) {
		return ((TipoMaquina) value).getNombre();
	}

}
